﻿using System;
using Styx;

namespace SuperbadWoD
{
    internal class Guardian
    {
        public static int active_enemies { get; set; }

        public static double gcd { get; set; }

        public static double incoming_damage_5 { get; set; }

        public static double incoming_damage_4s { get; set; }

        public static double incoming_damage_3 { get; set; }

        public static double incoming_damage_1s { get; set; }

        public void UpdateGuardianVariables()
        {
            active_enemies = active_enemies;
            gcd = gcd;
            incoming_damage_1s = incoming_damage_1s;
            incoming_damage_3 = incoming_damage_3;
            incoming_damage_4s = incoming_damage_4s;
            incoming_damage_5 = incoming_damage_5;
            action.savage_defense.charges_fractional = action.savage_defense.charges_fractional;
            buff.berserk.up = buff.berserk.up;
            buff.lacerate.stack = buff.lacerate.stack;
            buff.pulverize.remains = buff.pulverize.remains;
            buff.son_of_ursoc.up = buff.son_of_ursoc.up;
            buff.tooth_and_claw.react = buff.tooth_and_claw.react;
            buff.tooth_and_claw_absorb.down = buff.tooth_and_claw_absorb.down;
            cooldown.mangle.remains = cooldown.mangle.remains;
            cooldown.incarnation.remains = cooldown.incarnation.remains;
            dot.lacerate.duration = dot.lacerate.duration;
            dot.lacerate.remains = dot.lacerate.remains;
            dot.lacerate.stack = dot.lacerate.stack;
            dot.thrash_bear.duration = dot.thrash_bear.duration;
            dot.thrash_bear.remains = dot.thrash_bear.remains;
            health.max = health.max;
            talent.incarnation.enabled = talent.incarnation.enabled;
        }

        public static void GuardianRotation()
        {
            blood_fury();
            berserking();
            use_item(WoWInventorySlot.Trinket1);
            auto_attack();
            skull_bash();
            if (buff.tooth_and_claw.react && buff.tooth_and_claw_absorb.down && incoming_damage_1s > 0)
                if (maul())
                    return;
            if (incoming_damage_3 > (1 + action.savage_defense.charges_fractional)*0.04*health.max)
                if (frenzied_regeneration())
                    return;
            if (savage_defense())
                return;
            if (barkskin())
                return;
            if (incoming_damage_4s > health.max*0.15)
                if (bristling_fur())
                    return;
            if (incoming_damage_5 > 0.8*health.max)
                if (renewal())
                    return;
            if (!talent.incarnation.enabled || buff.son_of_ursoc.up || cooldown.incarnation.remains > 0)
                if (natures_vigil())
                    return;
            if (((dot.lacerate.remains <= dot.lacerate.duration*0.3) ||
                 (dot.lacerate.stack < 3 && dot.thrash_bear.remains > dot.thrash_bear.duration*0.3)) &&
                (buff.son_of_ursoc.up || buff.berserk.up))
                if (lacerate())
                    return;
            if (dot.thrash_bear.remains <= dot.thrash_bear.duration*0.3 && (buff.son_of_ursoc.up || buff.berserk.up))
                if (thrash_bear())
                    return;
            if (buff.pulverize.remains < gcd)
                if (pulverize())
                    return;
            if (mangle())
                return;
            if (incarnation())
                return;
            //TODO: CYCLE
            if (dot.lacerate.remains <= dot.lacerate.duration*0.3 || dot.lacerate.stack < 3)
                if (lacerate())
                    return;
            if (dot.thrash_bear.remains <= dot.thrash_bear.duration*0.3)
                if (thrash_bear())
                    return;
            if (cenarion_ward())
                return;
            if (active_enemies >= 3)
                if (thrash_bear())
                    return;
            lacerate();
        }

        private static void skull_bash()
        {
            throw new NotImplementedException();
        }

        private static bool natures_vigil()
        {
            throw new NotImplementedException();
        }

        private static bool pulverize()
        {
            throw new NotImplementedException();
        }

        private static bool incarnation()
        {
            throw new NotImplementedException();
        }

        private static bool bristling_fur()
        {
            throw new NotImplementedException();
        }

        private static bool thrash_bear()
        {
            throw new NotImplementedException();
        }

        private static bool cenarion_ward()
        {
            throw new NotImplementedException();
        }

        private static bool mangle()
        {
            throw new NotImplementedException();
        }

        private static bool lacerate()
        {
            throw new NotImplementedException();
        }

        private static bool renewal()
        {
            throw new NotImplementedException();
        }

        private static bool barkskin()
        {
            throw new NotImplementedException();
        }

        private static bool savage_defense()
        {
            throw new NotImplementedException();
        }

        private static bool frenzied_regeneration()
        {
            throw new NotImplementedException();
        }

        private static bool maul()
        {
            throw new NotImplementedException();
        }

        private static void auto_attack()
        {
            throw new NotImplementedException();
        }

        private static void use_item(WoWInventorySlot slot)
        {
            throw new NotImplementedException();
        }

        private static void berserking()
        {
            throw new NotImplementedException();
        }

        private static void blood_fury()
        {
            throw new NotImplementedException();
        }

        public class action
        {
            public class savage_defense
            {
                public static int charges_fractional { get; set; }
            }
        }

        public class buff
        {
            public class berserk
            {
                public static bool up { get; set; }
            }

            public class lacerate
            {
                public static int stack { get; set; }
            }

            internal class pulverize
            {
                public static double remains { get; set; }
            }

            public class son_of_ursoc
            {
                public static bool up { get; set; }
            }

            public class tooth_and_claw
            {
                public static bool react { get; set; }
            }

            public class tooth_and_claw_absorb
            {
                public static bool down { get; set; }
            }
        }


        public class cooldown
        {
            internal class incarnation
            {
                public static double remains { get; set; }
            }

            public class mangle
            {
                public static double remains { get; set; }
            }
        }

        public class dot
        {
            public class lacerate
            {
                public static double remains { get; set; }
                public static int stack { get; set; }
                public static int duration { get; set; }
            }

            public class thrash_bear
            {
                public static double remains { get; set; }
                public static double duration { get; set; }
            }
        }

        public class health
        {
            public static double max { get; set; }
        }

        public class talent
        {
            internal class incarnation
            {
                public static bool enabled { get; set; }
            }
        }
    }
}